package rsj.proxy.register;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import rsj.proxy.parse.SqlParse;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

/**
 * 创建mapper接口代理对象
 *
 * @author yuanqinglong
 * @since 2021/4/2 16:28
 */
public class MyMapperFactoryBean implements FactoryBean<Object> {

    private final Class<?> proxyInterface;

    public MyMapperFactoryBean(Class<?> proxyInterface) throws Exception {
        this.proxyInterface = proxyInterface;
        SqlParse.parse(proxyInterface);
    }

    @Autowired
    private InvocationHandler proxyInvokeHandler;

    @Override
    public Object getObject() throws Exception {
        return Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[]{proxyInterface}, proxyInvokeHandler);
    }


    @Override
    public Class<?> getObjectType() {
        return proxyInterface;
    }


}
